<?php

namespace app\admin\controller;
use app\common\model\Setup as SetupModel;
use app\common\controller\AdminBase;
use think\Config;
use think\Db;
use think\Session;
/**
 * 站点信息
 * Class Setup
 * @package app\admin\controller
 */
class Setup extends AdminBase
{
    protected $setup_model;

    protected function _initialize()
    {
        parent::_initialize();
        $this->setup_model = new SetupModel();

    }

    /**
     * 编辑站点信息
     * @param $id
     * @return mixed
     */
    public function edit()
    {
        $setup   = $this->setup_model->find(1);
        return $this->fetch('edit', ['setup' => $setup]);
    }

    /**
     * 更新站点信息
     * @param $id
     */
    public function update()
    {
        if ($this->request->isPost()) {
            $data            = $this->request->post();
            $validate_result = $this->validate($data, 'Setup');

            if ($validate_result !== true) {
                $this->error($validate_result);
            } else {
                $setup                     = $this->setup_model->find(1);
                $setup->id                 = 1;
                $setup->name               = $data['name'];
                $setup->title              = $data['title'];
                $setup->keywords           = $data['keywords'];
                $setup->description        = $data['description'];
                $setup->ico                = $data['ico'];
                $setup->copyright          = $data['copyright'];
                $setup->icp                = $data['icp'];
                $setup->template           = $data['template'];
                $setup->technology_name    = $data['technology_name'];
                $setup->technology_tel     = $data['technology_tel'];
                $setup->technology_url     = $data['technology_url'];

                if ($setup->save() !== false) {
                    $this->success('更新成功');
                } else {
                    $this->error('更新失败');
                }
            }
        }
    }

    
}
